package com.aigao.golf.common.config

import com.aigao.golf.common.file.fastDFS.pool.ConnectionPool
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.csource.fastdfs.ClientGlobal
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.beans.factory.annotation.Qualifier
import org.springframework.context.annotation.DependsOn
import org.springframework.context.annotation.Import
import java.util.*


/**
 * 文件配置
 */
@Configuration
class FileConfig{




    @Bean(name = ["pool"])
    @DependsOn("paramFactory")
    fun pool() : ConnectionPool{
        println("connectionPool")
        val p = Properties()
        p.setProperty("fastdfs.connect_timeout_in_seconds","10")
        p.setProperty("fastdfs.network_timeout_in_seconds","30")
        p.setProperty("fastdfs.charset","UTF-8")
        p.setProperty("fastdfs.http_tracker_http_port","80")
        p.setProperty("fastdfs.http_anti_steal_token","no")
        p.setProperty("fastdfs.http_secret_key",ParamFactory.fastdfsHttpSecretKey())
        p.setProperty("fastdfs.tracker_servers",ParamFactory.fastdfsTrackerServers())
        ClientGlobal.initByProperties(p)
        return ConnectionPool.getConnectionPool()
    }

//
//    @Bean
//    fun initStorageClient() : StorageClient1?{
//
//        var storageClient : StorageClient1?  = null
//        try {
//            ClientGlobal.init(FASTDFS_CONFIG)
//            println("ClientGlobal.configInfo(): " + ClientGlobal.configInfo())
//            val trackerClient = TrackerClient(ClientGlobal.g_tracker_group)
//            val trackerServer = trackerClient.connection ?: throw IllegalStateException("getConnection return null")
//            val storageServer = trackerClient.getStoreStorage(trackerServer) ?: throw IllegalStateException("getStoreStorage return null")
//            storageClient = StorageClient1(trackerServer, storageServer)
//        } catch (e: Exception) {
//            e.printStackTrace()
//        }
//
//        return storageClient
//
//    }

    companion object {
        val FASTDFS_CONFIG = "fdfs_client.conf"
    }


}
